Skip to content

refactor(models): align device parsing with DeviceResponseDto + nested state/location models#6

Open
kermz wants to merge 1 commit intoJonneDatanen:mainfrom
kermz:feat/improve-parsing
Open

refactor(models): align device parsing with DeviceResponseDto + nested state/location models#6
kermz wants to merge 1 commit intoJonneDatanen:mainfrom
kermz:feat/improve-parsing

Conversation

@kermz
Copy link
Copy Markdown

@kermz kermz commented Feb 26, 2026

Summary

This PR refactors device parsing to mirror the API response structure and strengthens integration coverage for mapping correctness.

What Changed

1. Refactored Models To Match API Shape

  • Added structured models in pythemo/models.py:
    • Device
    • DeviceState
    • DeviceParameters
    • LocationResponse
    • LockState enum
  • Switched from flattened device state fields to nested device.state.*.
  • Added mapping tables (ATTRIBUTES) for each model and parse/update loops driven by those mappings.
  • Added top-level DeviceResponseDto mapping on Device:
    • Id, Name, DeviceId, DeviceAuth, ClientId, Location,
    • EnvironmentId, EnvironmentName, Tags,
    • ActiveScheduleId, TemperatureSchedule, SW, State.
  • Added nested LocationResponseDto mapping on device.location.
  • Added nested DeviceStateDto mapping on device.state.
  • Added nested DeviceParameters mapping on device.state.device_parameters.

2. State/Value Handling

  • Added boolean normalization for 0/1 state flags:
    • lights (Lights)
    • frost_protection (FTS)
  • Added LockState enum parsing for Lock with tolerant fallback:
    • known values -> enum
    • unknown values -> preserved raw integer

3. Integration Test Expansion

  • Added tests/test_client.py integration mapping test to validate:
    • top-level Device mapping
    • nested LocationResponse mapping
    • nested DeviceState mapping
    • nested DeviceParameters mapping
  • Added mapping coverage checks:
    • fail on unmapped raw top-level keys
    • fail on unmapped raw State keys
    • fail on unmapped raw DeviceParameters keys
  • Added explicit comparison logs for all checks (OK/FAIL).
  • Added raw request/response logging in the mapping test:
    • RAW REQUEST
    • RAW RESPONSE

Files Updated

  • pythemo/models.py
  • tests/test_client.py
  • README.md

Notes

  • This is a model-structure change: consumers should now read state from device.state (instead of expecting flattened state fields directly on Device).
  • The integration mapping test is verbose by design for debugging parse/mapping discrepancies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant